﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PlayerTest.CustomControls
{
	/// <summary>
	/// ButtonImageControl.xaml에 대한 상호 작용 논리
	/// </summary>
	public partial class ImageButtonControl : UserControl
	{
        public ImageButtonControl()
		{
			this.InitializeComponent();
		}
        
        // 기본 출력 이미지
        private static readonly DependencyProperty DefaultImageProperty =
            DependencyProperty.Register(
           "DefaultImage",
           typeof(string),
           typeof(ImageButtonControl),
           //new FrameworkPropertyMetadata(false, ChangeDefaultImageProperty));
           new PropertyMetadata(null, new PropertyChangedCallback(ChangeDefaultImageProperty)));

        // 클릭시 출력 이미지
        private static readonly DependencyProperty PressedImageProperty =
            DependencyProperty.Register(
           "PressedImage",
           typeof(string),
           typeof(ImageButtonControl),
           //new FrameworkPropertyMetadata(false, ChangePressedImageProperty));
           new PropertyMetadata(null, new PropertyChangedCallback(ChangePressedImageProperty)));
        
        public string DefaultImage
        {
            get { return (string)GetValue(DefaultImageProperty); }
            set { SetValue(DefaultImageProperty, value); }
        }
        public string PressedImage
        {
            get { return (string)GetValue(PressedImageProperty); }
            set { SetValue(PressedImageProperty, value); }
        }

        private static void ChangeDefaultImageProperty(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ImageButtonControl button = d as ImageButtonControl;

            if (button != null)
            {
                button.ImageButtonCtrl.DefaultImage = (string)e.NewValue;
            }
        }

        private static void ChangePressedImageProperty(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ImageButtonControl button = d as ImageButtonControl;

            if (button != null)
            {
                button.ImageButtonCtrl.PressedImage = (string)e.NewValue;
            }
        }

        private static void ChangeClickProperty(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ImageButtonControl button = d as ImageButtonControl;

            if (button != null)
            {
                
            }
        }
        
        public delegate void ClickHandler(object sender, RoutedEventArgs e);
        public event ClickHandler Click;

        public void Button_Click(object sender, RoutedEventArgs e)
        {
            //execute daddy's button click
            //(((sender as Button).Parent as Grid).Parent as CustomButton).Click(sender, e);
            //if (Click != null) Click(this, EventArgs.Empty);
            if (Click != null) Click(this, e);

            e.Handled = false;

        }

        private void ImageButton_MouseEnter(object sender, MouseEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Hand;
        }

        private void ImageButton_MouseLeave(object sender, MouseEventArgs e)
        {
            Mouse.OverrideCursor = null;
        }
	}
}